package cuShapes;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import javax.xml.bind.annotation.XmlTransient;

class X_Compar implements Comparator<PQLine>{

	public int compare(PQLine l1, PQLine l2){		//parameter are of type Object, so we have to downcast it to Employee objects

			int line1 = ( (PQLine) l1 ).getStart().x;
			int line2 = ( (PQLine) l2 ).getStart().x;

			if( line1 > line2 ){
				return 1;
			}
			else if( line1 < line2 ){
				return -1;
			}
			else{
				return 0;
			}
	}
		
}

public class ArbShape extends Connectable{
	
	@XmlTransient
	private static final long serialVersionUID = 1L;
	@XmlTransient
	private static int nameCount = 0;
	
	public ArbShape(ArrayList<PQLine> lineList){
		super();
		name = "ArbShape #" + Integer.toString(nameCount++);
				
		Collections.sort(lineList,new X_Compar());
		Point tl = lineList.get(0).getStart();
		Point br = lineList.get(lineList.size()-1).getStart();
		
		for(PQLine l: lineList){
			lines.add(l);
			
		}
		
		
		width = 100;
		height = 100;
		
		center = new Rectangle(tl.x+(width/2)-5,tl.y+(height/2)-5,10,10);
		resize = new Rectangle(br.x-5,br.y-5,10,10);
		rect = new Rectangle(tl.x,tl.y,width, height);
		
	}

	@Override
	public int getHeight() {
		return Math.abs(height);
	}

	@Override
	public String getShapeClass() {
		return "ArbShape";
	}

	@Override
	public int getWidth() {
		return Math.abs(width);
	}

	@Override
	public boolean hitRect(Point p) {
			boolean ret = false;
			if(center.contains(p)){
				workingRect = center;
				ret = true;
			}
			else if(resize.contains(p)){
				workingRect = resize;
				ret = true;
			}
			return ret;
	}

	@Override
	public void moveWorkingRect(Point p) {
		// TODO Auto-generated method stub
		
	}

}
